home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 5532 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.4 KB

  1. Path: newshost.lanl.gov!tanmoy
  2. From: tanmoy@qcd.lanl.gov (Tanmoy Bhattacharya)
  3. Newsgroups: comp.os.msdos.programmer,comp.lang.c
  4. Subject: Re: open vs fopen?
  5. Date: 08 Feb 1996 00:15:53 GMT
  6. Organization: Los Alamos National Laboratory
  7. Distribution: na
  8. Message-ID: <TANMOY.96Feb7171553@qcd.lanl.gov>
  9. References: <uEYFxc9nX8WX083yn@mbnet.mb.ca> <4f8qf1$h3b@ssbunews.ih.att.com>
  10. NNTP-Posting-Host: qcd.lanl.gov
  11. Mime-Version: 1.0
  12. Content-Type: text
  13. In-reply-to: bamford@marconi.ih.att.com's message of 7 Feb 1996 00:06:57 GMT
  14.  
  15. In article <4f8qf1$h3b@ssbunews.ih.att.com> bamford@marconi.ih.att.com
  16. (Harold E. Bamford) writes: 
  17.    >In C, why would one use open and DOS int handles rather than fopen and
  18.    >stdio file handles?
  19.    >
  20.    >Is there some speed advantage or differnet functionality?
  21.  
  22.    open() is for raw I/O.  You use read(), write(), lseek(), ltell()
  23.  
  24.    fopen() is for buffered I/O.  You can use fread(), fscanf(), fgets(),
  25.    getchar(), putchar, fprint(), fwrite(), fseek(), ftell(), etc.
  26.                        ^^^^^^???
  27.  
  28. You can specify that fopen etc. should not buffer at the level of the
  29. C library. Whether there are further buffers up or down stream is an
  30. OS issue.
  31.  
  32.    For certain applications, you can get away without buffering.  But
  33.    often it is easier to do the programming if you don't have to worry
  34.    about unneeded system calls and buffering gives you that.
  35.  
  36.    Raw I/O is faster if you are, for instance, sucking the entire contents
  37.    of a file into memory at once.
  38.  
  39.    Buffered I/O tends to automatically include parts of the standard C
  40.    library that you may not need (*printf* stuff).
  41.  
  42. Why?
  43.  
  44.    It depends on your goal.  And usually the reasons for using one or the
  45.    other are operating system independent.
  46.  
  47. And, very importantly, fopen etc. are defined in the C standard, and
  48. hence, code using it is maximally portable. open and its relatives are
  49. are not defined by the C standard. (They are defined by other
  50. standards, but that is a different issue.)
  51.  
  52. Cheers
  53. Tanmoy
  54. --
  55. tanmoy@qcd.lanl.gov(128.165.23.46) DECNET: BETA::"tanmoy@lanl.gov"(1.218=1242)
  56. Tanmoy Bhattacharya O:T-8(MS B285)LANL,NM87545 H:#9,3000,Trinity Drive,NM87544
  57. Others see <gopher://yaleinfo.yale.edu:7700/00/Internet-People/internet-mail>,
  58. <http://alpha.acast.nova.edu/cgi-bin/inmgq.pl>or<ftp://csd4.csd.uwm.edu/pub/
  59. internetwork-mail-guide>. -- <http://nqcd.lanl.gov/people/tanmoy/tanmoy.html>
  60. fax: 1 (505) 665 3003   voice: 1 (505) 665 4733    [ Home: 1 (505) 662 5596 ]
  61.